<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Cache;

class Job extends Controller
{

    public function index(){
        $link = Db::name('link')->select();
        $this->assign('link',$link);
        $cat = Db::name('cat')->select();
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $ad = Db::name('info')->where('areaid',1)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',1)->select();
        $info = Db::name('info')
            ->alias('a')
            ->join('cat c','a.catid = c.cat')
            ->where('areaid',1)
            ->order('ding desc')->select();
        $this->assign('cat',$cat);
        $this->assign('tui',$tui);
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $this->assign('info',$info);
        $area = '北京';
        $this->assign('area',$area);
        $site = 'http://m.bjinfo.com';
        $this->assign('site',$site);
        $c = Db::name('config')->where('id',1)->find();
        $this->assign('c',$c);
        return $this->fetch('index/index');
    }

    public function job(){
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $ad = Db::name('info')->where('areaid',1)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',1)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);
        $info = Db::name('info')
            ->alias('a')
            ->join('cat c','a.catid = c.cat')
            ->where('areaid',1)
            ->order('ding desc')->select();
        $this->assign('info',$info);
        $area = '北京';
        $this->assign('area',$area);
        $site = 'http://m.bjinfo.com';
        $this->assign('site',$site);
        $c = Db::name('config')->where('id',1)->find();
        $this->assign('c',$c);
        return $this->fetch('index/job');
    }

    public function info(){
        $info = Db::name('info')->where('id',input('id'))->find();
        $this->assign('h',$info);
        $cat = Db::name('cat')->select();
        $this->assign('cat',$cat);
        $cate = Db::name('cat')->where('cat',$info['catid'])->find();
        $this->assign('cate',$cate);
        $ad = Db::name('info')->where('areaid',1)->limit(10)->select();
        $adv = Db::name('ad')->where('areaid',1)->select();
        $this->assign('ad',$ad);
        $this->assign('adv',$adv);
        $tui = Db::name('info')->where('tui',1)->limit(10)->select();
        $this->assign('tui',$tui);

        $area = '北京';
        $this->assign('area',$area);
        $site = 'http://m.bjinfo.com';
        $this->assign('site',$site);
        $c = Db::name('config')->where('id',1)->find();
        $this->assign('c',$c);
        $ding = Db::name('info')->order('ding desc')->limit(20)->select();

        $this->assign('ding',$ding);

        $uid =  Db::name('info')->where('id',input('id'))->value('uid');
        $message =  Db::name('message')->where('uid',$uid)->select();
        $this->assign('message',$message);

        return $this->fetch('index/info');
    }
    public function publish(){
        return $this->fetch('index/publish');
    }

    public function message(){
        if(input('post.')) {
            $mobile = input('mobile');
            $uid =  Db::name('info')->where('id',input('id'))->value('uid');
            Db::name('message')->insert([
                'uid'=>$uid,
                'mobile'=>$mobile,
                'time'=>time(),
            ]);
            $this->success('提交成功');
        }
    }
}